import { createCmdConfig, DisposableCollection, uuidv4 } from '@antv/xflow'

export const useCmdConfig = createCmdConfig(config => {
  config.setRegisterHookFn(hooks => {
    const list = [
      hooks.addNode.registerHook({
        name: 'set node config',
        handler: async args => {
          console.log(args.nodeConfig.id);
          
          args.nodeConfig = {
            ...args.nodeConfig,
            // id: args.nodeConfig.id || `node-${uuidv4()}`
          }
        }
      }),
      hooks.addEdge.registerHook({
        name: 'set node edge',
        handler: async args => {
          args.edgeConfig = {
            ...args.edgeConfig
            // zIndex: 0,
            // attrs: {
            //   line: {
            //     stroke: '#A2B1C3',
            //     targetMarker: {
            //       name: 'block',
            //       width: 12,
            //       height: 8,
            //     },
            //     strokeWidth: 1,
            //   },
            // },
          }
        }
      })
    ]
    const toDispose = new DisposableCollection()
    toDispose.pushAll(list)
    return toDispose
  })
})
